<!DOCTYPE html>
<html>
<head>
    <title>Type</title>
</head>
<body>
<input id="input" value="input"/>

<script>
    let keydownRaised = false;
    let keypressRaised = false;
    let inputRaised = false;
    let keydownCount = 0;
    let keypressCount = 0;

    document.getElementById('input').addEventListener('keydown', function () {
        keydownRaised = true;
        keydownCount++;
    });

    document.getElementById('input').addEventListener('keypress', function () {
        keypressRaised = true;
        keypressCount++;
    });

    document.getElementById('input').addEventListener('input', function () {
        inputRaised = true;
    });

    document.getElementById('input').addEventListener('keyup', function () {
        const isAndroid           = /Android/i.test(navigator.userAgent);
        const containsAllText     = this.value.indexOf('block of text to be inserted in one keystroke') > 0;
        const allRaised           = keydownRaised && keypressRaised || isAndroid && inputRaised;
        const exactlyOneKeystroke = keydownCount === 1 && keypressCount === 1 || isAndroid;

        if (allRaised && this.value === 'a') {
            throw new Error('Type in input raised');
        } else if (allRaised && exactlyOneKeystroke && containsAllText) {
            throw new Error('Type block in one keystroke raised');
        }
    });
</script>
</body>
</html>
